<#include "../common/_layout.html"/>
<@layout>
	<section class="top clearfix">
			<ul class="clearfix login_nav">
				<li <#if (type == 1)> class="active" </#if> onclick="window.location='/index?type=1'">寻活儿</li>
			    <li <#if (type == 2)> class="active" </#if> onclick="window.location='/index?type=2'">寻房</li>
			    <li <#if (type == 3)> class="active" </#if> onclick="window.location='/index?type=3'">买卖</li>
			    <li <#if (type == 4)> class="active" </#if> onclick="window.location='/index?type=4'">活动</li>
			    <li <#if (type == 5)> class="active" </#if> onclick="window.location='/index?type=5'">问答</li>
			</ul>
      </section>
       
   	 <p class="demo-desc">${(info.title)!}</p>
	 <div class="demo-block"> 	  
	    <div class="ui-whitespace">
	    	<#if (type == 1)>
	    	   <p class="ui-txt-highlight">${(info.price_range)!}</p>
	    	   <p>招聘类别 ：${(info.category)!}</p>
               <p>招聘人数：${(info.amount)!}</p>
               <p>招聘单位：${(info.company)!}</p>
               <p>工作地址：${(info.address)!}</p>
            </#if>
            
            <#if (type == 2)>
            	<p class="ui-txt-highlight">${(info.price)!}元/月</p>
            	<p>房源类别 ：${(info.category)!}</p>
            	<p>房源地址 ：${(info.address)!}</p>
            </#if>  
            
            <#if (type == 3)>
            	<p class="ui-txt-highlight"><#if info.price??>${(info.price)!}元</#if></p>
            	<p>买卖类别 ：${(info.category)!}</p>
            	<p>交易地址 ：${(info.address)!}</p>
            </#if> 
            
            <#if (type == 4)>
            	<p class="ui-txt-highlight"><#if info.price??>${(info.price)!}元<#else>免费</#if></p>
            	<p>主办方：${(info.company)!}</p>
            	<p>活动类别 ：${(info.category)!}</p>
            	<p>活动地址 ：${(info.address)!}</p>
            </#if>
            
            <#if (type != 5)>
             	<p>联&nbsp;&nbsp;系&nbsp;&nbsp;人：${(info.contacts)!}</p>
               <p>联系电话：${(info.mobile)!}</p>
               <p>联系QQ：${(info.qq)!}</p>
            </#if>
              
               <p>发布日期：${(info.createDateStr)!}</p>
           </div>
	  </div> 
					         
      <div class="demo-block"> 
           
           <div class="ui-flex ui-flex-ver ui-flex-pack-center ui-flex-align-start">
               <div style="margin-left: 10px"><b>描述</b></div>
			   <div>${(info.description)!}</div>
		   </div>
			
		   <#if (type == 1)>	
		   <div class="ui-flex ui-flex-ver ui-flex-pack-center ui-flex-align-start">
               <div style="margin-left: 10px"><b>公司简介</b></div>
               <div>${(info.introduce)!}</div>
           </div>
           </#if>
	 </div>
     
<!--       <div class="demo-item">
        <div class="demo-block">
            <ul class="ui-list ui-list-text ui-border-tb" id="gb_ul">
                <li class="ui-border-t" >
                    <h6><a>张三</a>我我我我我我</h6>&nbsp;&nbsp;<button class="ui-btn-s ui-btn-danger" onclick="del()">删除</button>
                 </li>
                <li class="ui-border-t" >
                    <h6><a>张三</a>回复<a>李四</a>我我我我我我</h6>
                </li>
            </ul>
        </div>
     </div>  -->
     
     <#if guestBookPage??>
     <div class="demo-item">
        <div class="demo-block">
            <ul class="ui-list ui-list-text ui-border-tb" id="gb_ul">
            	<#list guestBookPage.getList() as x>
                <li class="ui-border-t" <#if (session['wechat_user']?? && session['wechat_user'].id!=x.from_user_id)> onclick="to_publish(this)" from_user_name="${(x.fromUserName)!}" from_user_id="${(x.from_user_id)!}" parent_id="${(x.parent_id)!}"</#if> msg_id="${(x.id)!}">
                    <h6><a>${(x.fromUserName)!}</a><#if (x.to_user_id > 0)>回复<a>${(x.toUserName)!}</a></#if>：${(x.content)!}</h6>
                    <#if (session['wechat_user']?? && session['wechat_user'].id==x.from_user_id)>&nbsp;&nbsp;<input type="button" class="ui-btn-s ui-btn-danger" onclick="del(this, ${x.id})" value="删除"></#if>
                </li>
                	<#list x.getChildGuestBook() as y>
                		  <li class="ui-border-t" <#if (session['wechat_user']?? && session['wechat_user'].id!=y.from_user_id)> onclick="to_publish(this)" from_user_name="${(y.fromUserName)!}" from_user_id="${(y.from_user_id)!}" parent_id="${(y.parent_id)!}"</#if> msg_id="${(y.id)!}">
			                    <h6><a>${(y.fromUserName)!}</a><#if (y.to_user_id > 0)>回复<a>${(y.toUserName)!}</a></#if>：${(y.content)!}</h6>
			                    <#if (session['wechat_user']?? && session['wechat_user'].id==y.from_user_id)>&nbsp;&nbsp;<input type="button" class="ui-btn-s ui-btn-danger" onclick="del(this, ${y.id})" value="删除"></#if>
			              </li>
                	</#list>
                </#list>
            </ul>
             <!-- Loading Start -->
			<div id="xs_load" style="width:110px;height:37px;margin:0 auto;text-align: center;display:none;" class="clearfix">
				 <span style="color:#777;font-size:12px; margin-top: 5px;text-align:center;margin-top:10px;display:none;">松开加载更多</span>
		  	</div>
			<!-- Loading End -->
			<input type="hidden" id="xs_total" value="${(guestBookPage.totalRow)!}" />
        </div>
     </div>  
     </#if>
     
     <div class="demo-item">
        <div class="demo-block">
        	<form id="guestBookForm">
            <section class="ui-input-wrap ui-border-t">
                <div class="ui-input ui-border-radius">
                    <input type="text" id="message" name="guestBook.content" placeholder="我也说一句...">
                    <input type="hidden" id="to_user_id" name="guestBook.to_user_id" value="0"/>
                    <input type="hidden" id="parent_id" name="guestBook.parent_id" value="0"/>
                    <input type="hidden" name="guestBook.info_id" value="${info.id}"/>
                </div>
                <input type="button" class="ui-btn" onclick="publish('<#if session['wechat_user']??>${session['wechat_user'].nick}</#if>')" value="发表"/>
                <input type="button" class="ui-btn" onclick="emptyForm()" value="清空"/>
            </section>
            </form>
         </div>
    </div>   
    
    <script type="text/javascript">
    var page = 2,_limit=10,_total=0,curr_total=10,is_exe=true;
    var _loadHtml = '<div  id="_loading" style="font-size:12px;text-align:center;margin-top:20px;"><img src="static/frozenui/img/loading_img.gif" style="width:20px;height:20px;vertical-align:middle;margin-right:5px;">加载中,请稍等</div>';
    var _loadMore = '<span  id="_load_more" style="color:#777;font-size:12px;">松开加载更多</span>';
    var _noData = '<span  id="_no_data" style="color:#777;font-size:12px;">暂无数据</span>';
    $(function(){
    	_total = parseInt($("#xs_total").val());
    	if(_total > curr_total){$('#xs_load').show()}else{is_exe=false;};
    	//auto load
    	var offsettop = 800;
    	document.onscroll = function(){
    	   var xs_div = document.getElementById('gb_ul');
    	   var xs_d_h = xs_div.scrollHeight;
    	   var docTop = document.body.scrollTop | document.documentElement.scrollTop;
    	    docTop += offsettop;
    	   if(docTop > xs_d_h){
    		  if(is_exe){
    			  is_exe = false;
    			  $('#xs_load').html('').append(_loadHtml);
    			  setTimeout('loadMore()',300);
    		  }
    	   }
    	};
    })

    //加载更多
    function loadMore(){
    	var params = {};
    	params.page = page;
    	$.post("guestbook/guestBookList",params,function(mes){
    		if(mes.code == 200) {
    			var _data = mes.data.list;
    			_total = mes.data.totalRow;
    			var _html = '';
    			var curr_user_id = 0;
    			<#if session['wechat_user']??>curr_user_id = ${session['wechat_user'].id}</#if>
    			
    			$.each(_data,function(k,v){
    				var href  = '';
    				var delbut = '';
    				if(curr_user_id != v.from_user_id){
    					href = 'onclick="to_publish(this)" from_user_name="'+v.fromUserName+'" from_user_id="'+v.from_user_id+'" parent_id="'+v.parent_id;
    				}else{
    					delbut = '&nbsp;&nbsp;<input type="button" class="ui-btn-s ui-btn-danger" onclick="del(this, '+v.id+')" value="删除">';
    				}
    				var reploy = '';
    				if(v.to_user_id > 0){
    					reploy = '回复<a>'+v.toUserName+'</a>';
    				}
    				_html += '<li class="ui-border-t"' + href +' msg_id="'+  v.id +'">'+
    		                    '<h6><a>'+v.fromUserName+'</a>'+reploy+':'+v.content+'</h6>'+delbut+
    		                '</li>';
    		                
    				$.each(v.childGuestBook,function(k,v){
        				if(curr_user_id != v.from_user_id){
        					href = 'onclick="to_publish(this)" from_user_name="'+v.fromUserName+'" from_user_id="'+v.from_user_id+'" parent_id="'+v.parent_id;
        				}else{
        					delbut = '&nbsp;&nbsp;<input type="button" class="ui-btn-s ui-btn-danger" onclick="del(this, '+v.id+')" value="删除">';
        				}
        				var reploy = '';
        				if(v.to_user_id > 0){
        					reploy = '回复<a>'+v.toUserName+'</a>';
        				}
        				_html += '<li class="ui-border-t"' + href +' msg_id="'+  v.id +'">'+
        		                    '<h6><a>'+v.fromUserName+'</a>'+reploy+':'+v.content+'</h6>'+delbut+
        		                '</li>';
        		                
        		                
        			});       
    			});
    			
    			//无数据判定Start
    			if(page == 1 && _total == 0){
    				$('#xs_load').append(_noData);
    			}
    			//无数据判定End
    			//判定是否有跟多数据Start
    			curr_total = page * _limit;
    			if(curr_total < _total){
    				is_exe = true;
    				page++;
    				$('#xs_load').append(_loadMore);
    			}

    			//判定是否有跟多数据End
    			if(page == 1){
    				$('#xs_list').html('').append(_html);
    			}else{
    				$('#xs_list').append(_html);
    			}
    			$('.ui-loading-block').remove();		
    		}else{
    			var el;
    			el=$.tips({
    				content:'服务器繁忙...',
    				stayTime:2000,
    				type:"info"
    			});
    		}

    		$("#_loading").remove();
    	});
    }
    
        var curr_obj;
    	function to_publish(obj){
    		curr_obj = obj;
    		document.getElementById('message').scrollIntoView();
    		$("#message").attr("placeholder", "回复"+$(obj).attr("from_user_name")+":").focus();
    		$("#to_user_id").val($(obj).attr("from_user_id"));
    		$("#parent_id").val($(obj).attr("parent_id")==0 ? $(obj).attr("msg_id") : $(obj).attr("parent_id"));
    	}
    	
    	function publish(nick){
    		if(!$("#message").val()){
    			tips("请填写发表内容");
    			return false;
    		}
    		
    		$.ajax({
   	         type: "post",
   	         url: "guestbook/save",
   	         data:$("#guestBookForm").serialize(),// 要提交的表单 
   	         success:function(data){
   	        	  var msg = data.msg;
   		          if(data.code==200){
   		        	  msg = "发表成功";
   		     	  	  if(curr_obj){
   		     	  		$("#gb_ul").append("<li class=\"ui-border-t\"><h6><a>" + nick + "</a>回复<a>" + $(curr_obj).attr("from_user_name") + "</a>：" + $("#message").val() + "</h6>&nbsp;&nbsp;<input type=\"button\" class=\"ui-btn-s ui-btn-danger\" value=\"删除\" onclick=\"del(this, " + data.data.id + ")\"></li>");
		              }else{
		            	$("#gb_ul").append("<li class=\"ui-border-t\"><h6><a>" + nick + "</a>：" + $("#message").val() + "</h6>&nbsp;&nbsp;<input type=\"button\" class=\"ui-btn-s ui-btn-danger\" value=\"删除\" onclick=\"del(this, " + data.data.id + ")\"></li>");
		              }
   		          }
   		       	  emptyForm();
   		       	  tips(msg);
   		       }
   	   	 });
    	}
    	
    	function emptyForm(){
    		curr_obj = null;
    		$("#message").val("");
    		$("#message").attr("placeholder", "我也说一句...");
    		$("#to_user_id").val(0);
    		$("#parent_id").val(0);
    		$("#message").val("");
    	}
    	
    	function del(obj, id){
			 if(confirm("确定要删除吗？")){
				 $.ajax({
			         type: "post",
			         url: "guestbook/delete",
			         data:{id:id},
			         success:function(data){
			        	 tips("删除成功");
						 $(obj).parent().remove();
				       }
			    });
				
			 }
		}
    </script>
</@layout>        